package weeklyContest;

/**
 * @author zhangmin
 * @create 2021-09-26 10:28
 */
public class weekly_contest_260 {

    public int maximumDifference(int[] nums) {
        int n=nums.length;
        int[] cz=new int[n];
        int res=-1;
        for (int i = 0; i < n-1; i++) {
            for (int j = i+1; j < n; j++) {
                if (nums[j]<=nums[i])
                    continue;
                if (nums[i]<nums[j]);
                res=Math.max(res,nums[j]-nums[i]);
            }
        }
        return res;
    }

    public long gridGame(int[][] grid) {
        int n=grid[0].length;
        int index=0;
        int max=0;
        int[][] m=new int[2][n];
        m[0][0]=grid[0][0];
        m[1][0]=grid[1][0];
        for (int i = 1; i < n; i++) {
            m[0][i]=m[0][i-1]+grid[0][i];
            m[1][i]=m[1][i-1]+grid[1][i];
        }
        System.out.println(m[0][n-1]+","+m[1][n-1]);
        for (int i = 0; i < n; i++) {
            int[][] g=grid;
            for (int j = 0; j<n ; j++) {
                if (j<=i){
                    g[0][j]=0;
                }
                if (i>=index){
                    g[1][j]=0;
                }
            }
            int[][] m2=new int[2][n];
            m2[0][0]=0;
            m2[1][0]=g[1][0];
            for (int j = 1; j < n; i++) {
                m2[0][j]=m2[0][j-1]+g[0][j];
                System.out.println("1:"+m2[0][j]);
                m2[1][j]=m2[1][j-1]+g[1][j];
                System.out.println("2:"+m2[1][j]);
            }
            System.out.println(m2[0][n-1]+","+m2[1][n-1]);
            index=0;
            max=0;
            for (int j = 0; j < n; j++) {
                int sum=m2[0][j]+m2[1][n-1]-m2[1][j]+g[1][j];
                System.out.println("sum="+sum);
                if (sum>max){
                    max=sum;
                    index=i;
                }
            }
        }
        System.out.println("index="+index);


        return max;
    }

    public static void main(String[] args) {
        int[][] grid=new int[][]{{20,3,20,17,2,12,15,17,4,15},{20,10,13,14,15,5,2,3,14,3}};
        weekly_contest_260 obj=new weekly_contest_260();
        System.out.println(obj.gridGame(grid));
    }
}
